package org.easyframework.bad.core.scm;

import java.io.InputStream;

import org.easyframework.bad.core.CLExecutor;
import org.easyframework.bad.core.CLTask;
import org.easyframework.bad.core.ProcessStreamReader;

public class SVN extends SCM {

	private String localWorkingCopy;
	private String userName;
	private String password;

	@Override
	public void update() {

	}

	public void execute() {
		CLTask task = new CLTask();

		task.setExecutable("svn");

		task.addArg("checkout");

		task.setWorkingDirectory(localWorkingCopy);

		task.addArg(getRepositoryLocation());

		if (userName != null) {
			task.addArg("--username");
			task.addArg(userName);
		}

		Process process = CLExecutor.exec(task);

		try {
			StringBuffer inBuffer = new StringBuffer();
			InputStream inStream = process.getInputStream();
			new ProcessStreamReader(inBuffer, inStream);

			StringBuffer errBuffer = new StringBuffer();
			InputStream errStream = process.getErrorStream();
			new ProcessStreamReader(errBuffer, errStream);

			process.waitFor();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public void execute(String[] args) {
	}

	public String getLocalWorkingCopy() {
		return localWorkingCopy;
	}

	public void setLocalWorkingCopy(String localWorkingCopy) {
		this.localWorkingCopy = localWorkingCopy;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
}
